<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
    .asLabel .mini-textbox-border,
    .asLabel .mini-textbox-input,
    .asLabel .mini-buttonedit-border,
    .asLabel .mini-buttonedit-input,
    .asLabel .mini-textboxlist-border
    {
        border:0;background:none;cursor:default;
    }
    .asLabel .mini-buttonedit-button,
    .asLabel .mini-textboxlist-close
    {
        display:none;
    }
    .asLabel .mini-textboxlist-item
    {
        padding-right:8px;
    }    
    </style>
</head>

<body>
	<form id="form1" method="post">
		<div style="padding-left:30px;padding-bottom:5px;padding-top: 25px;">
            <table style="table-layout:fixed;" cellspacing="0" cellpadding="10">
               <tr>
               		<td>姓名：<input class="mini-textbox asLabel" enabled="false" value="<sec:authentication property="principal.name"></sec:authentication>" readOnly="true" style="margin-left:32px;width: 180px;" /></td>
               </tr>
               <tr>
                    <td>开始时间：<input name="startTime"  class="mini-datepicker" 
                    	required="true" style="width: 180px" onvaluechanged="sumdays" ondrawdate="onDrawDate" showClearButton="false" allowInput="false"/></td>
                    <td>结束时间：<input name="endTime" onvaluechanged="sumdays" ondrawdate="onEndDate" class="mini-datepicker" showClearButton="false" required="true" style="width: 180px" allowInput="false"/>
                	</td>
           			<td>共：<input name="days" vtype="range:1,500" class="mini-textbox" required="true" enabled="false" style="width: 60px"/>天
                    </td>
                </tr>
                <tr>
                	<td>休假类型：<input name="leaveType"    
                		class="mini-combobox" required="true" valueField="keyName" style="width: 180px" textField="keyValue" url="dictionary_key_val_view.do?typeName=LEAVE_TYPE"/>
                	</td>
                </tr>
            </table>
            <div style="text-align:left;padding:10px;">
            	  <div>休假原因：</div>
                  <input name="description" class="mini-textarea" style="margin-left:80px;height:80px;width: 700px;" required="true" />
            </div>
        </div>
        <input name="id" class="mini-hidden"/>
        <div style="margin-top:30px;text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:100px;margin-right:50px;">申请休假</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>
	</form>
</body>

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	
	function SaveData() {
        var o = form.getData(true);            

        form.validate();
        if (form.isValid() == false) return;
        $.ajax({
            url: "leave_infoedit_save.do",
			type: 'post',
			dataType: 'json',
            data: o,
            cache: false,
            success: function (text) {
            	if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误，请重新编辑");
	            }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
            }
        });
    }
	
	function sumdays(){
		var startTime = mini.getbyName("startTime").getFormValue();
		var endTime = mini.getbyName("endTime").getFormValue();
		var days = mini.getbyName("days");
		if(endTime){
			if(startTime == endTime){
				days.setValue("1");
			}else{
				var cuttime = (Date.parse(startTime) - Date.parse(endTime)) / 86400000;
				if(cuttime > 0) {
					days.setValue(day + 1);	//加一代表包含当天
				} else {
					days.setValue(day);	//减一代表包含当天
				}
			}
		}else{
			days.setValue("");
		}
	}
	
	function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        d.setDate(d.getDate() - 1);
        if (date.getTime() < d.getTime()) {
            e.allowSelect = false;
        }
    }
	
	function onEndDate(e){
		var start = mini.getbyName("startTime").getValue();
		if(e.date.getTime() < start.getTime()){
			e.allowSelect = false;
		}
	}
	
	$(function(){
		mini.getbyName("startTime").setValue(new Date());
		mini.getbyName("endTime").setValue(new Date());
		sumdays();
	});
	
	function onOk(e) {
        SaveData();
    }
	
	function SetData(data){
	     data = mini.clone(data);
	     form.setData(data.row);
	}
	
	function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
	
	function onCancel(e) {
        CloseWindow("cancel");
    }

</script>